#pragma once

#include "sqlite3.h"

namespace SQLite {

	ref class Database; 

	public ref class Statement sealed {
	private:
		sqlite3_stmt* stmt;
	public:
		property bool Valid;
		Statement(Database^ database, Platform::String^ cmd);
		~Statement() {
			sqlite3_finalize(stmt);
		}
		bool Execute() {
			int rc = sqlite3_step(stmt);
			return rc == SQLITE_DONE;
		}
		bool HasMore() {
			int rc = sqlite3_step(stmt);
			return rc == SQLITE_ROW;
		}
		Platform::String^ ColumnAsTextAt(int index) {
			return ref new Platform::String((const wchar_t*) sqlite3_column_text16(stmt, index));
		}
		int ColumnAsIntAt(int index) {
			return sqlite3_column_int(stmt, index);
		}
		int ColumnAsDoubleAt(int index) {
			return sqlite3_column_double(stmt, index);
		}
		bool BindText(int index, Platform::String^ param) {
			int rc = sqlite3_bind_text16(stmt, index, param->Data(), -1, SQLITE_STATIC);
			return rc == SQLITE_OK;
		}
		bool BindInt(int index, int param) {
			int rc = sqlite3_bind_int(stmt, index, param);
			return rc == SQLITE_OK;
		}
		bool BindDouble(int index, double param) {
			int rc = sqlite3_bind_double(stmt, index, param);
			return rc == SQLITE_OK;
		}
	};

}
